use "replicationDS.dta", clear

* FIGURE 2: 
scatter v2x_corr v2x_polyarchy, mcolor(gs14) msize(vtiny) || qfit v2x_corr v2x_polyarchy, lwidth(thick) ||, ytitle("Corruption Index") xtitle("Electoral Democracy") xscale(range(0 1)) yscale(range(0 1)) ylabel(0(.2)1) xlabel(0 "low" 1 "high") title("") graphregion(color(white)) legend(region(lcolor(white)))

eststo clear
* TABLE 1:
* (1) Cross-sectional, no country-fe's, only year-fe's
eststo pol1: qui regr v2x_corr l.v2x_corr l2.v2x_corr c.l.v2x_polyarchy##c.l.v2x_polyarchy i.year, cluster(country_id)
* (2) Adding country fe's
eststo pol2: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr c.l.v2x_polyarchy##c.l.v2x_polyarchy i.year, fe cluster(country_id)
* (3) Adding controls
* Only controlling for gdp + stock
eststo pol3: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr c.l.v2x_polyarchy##c.l.v2x_polyarchy l.polyarchy_stock10 l.e_migdppc i.year, fe cluster(country_id)
* (4) Adding interaction with GDP
eststo pol4: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr c.l.v2x_polyarchy##c.l.v2x_polyarchy l.polyarchy_stock10 l.e_migdppc c.l.e_migdppc#c.l.v2x_polyarchy i.year, fe cluster(country_id)
* (5) Showing robust even with disaggregated corruption
eststo pol5: qui xtreg v2x_execorr l.v2x_execorr l2.v2x_execorr c.l.v2x_polyarchy##c.l.v2x_polyarchy l.polyarchy_stock10 l.e_migdppc c.l.e_migdppc#c.l.v2x_polyarchy i.year, fe cluster(country_id)
esttab pol1 pol2 pol3 pol4 pol5, b(4) se(4) star(* 0.10 ** 0.05 *** 0.01) replace nogaps keep(L.v2x_corr L2.v2x_corr L.v2x_execorr L2.v2x_execorr L.v2x_polyarchy cL.v2x_polyarchy#cL.v2x_polyarchy L.polyarchy_stock10 L.e_migdppc cL.e_migdppc#cL.v2x_polyarchy) order(L.v2x_corr L2.v2x_corr L.v2x_execorr L2.v2x_execorr L.v2x_polyarchy cL.v2x_polyarchy#cL.v2x_polyarchy L.polyarchy_stock10 L.e_migdppc cL.e_migdppc#cL.v2x_polyarchy) label sca("r2" "N_g" "g_avg") obslast addnotes("Entries are regression coefficients, with standard errors clustered on countries, in parentheses. Country- and year-fixed effects included in regressions but omitted from the table.")

* TABLE 2:
eststo free1: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr L.v2x_freexp_thick cL.v2x_freexp_thick#cL.v2x_freexp_thick l.polyarchy_stock10 i.year, fe cluster(country_id)
* (H2) Curvilinear effect of freedom of association
eststo free2: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr L.v2x_frassoc_thick cL.v2x_frassoc_thick#cL.v2x_frassoc_thick l.polyarchy_stock10 i.year, fe cluster(country_id)
* Controlling for media freedom separate from freedom of expression
eststo free3: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr L.v2x_freexp_thick cL.v2x_freexp_thick#cL.v2x_freexp_thick l.e_mefree l.polyarchy_stock10 i.year, fe cluster(country_id)
esttab free1 free2 free3, b(4) se(4) star(* 0.10 ** 0.05 *** 0.01) replace nogaps keep (L.v2x_corr L2.v2x_corr L.v2x_freexp_thick cL.v2x_freexp_thick#cL.v2x_freexp_thick L.v2x_frassoc_thick cL.v2x_frassoc_thick#cL.v2x_frassoc_thick L.e_mefree) order (L.v2x_corr L2.v2x_corr L.v2x_freexp_thick cL.v2x_freexp_thick#cL.v2x_freexp_thick L.e_mefree L.v2x_frassoc_thick cL.v2x_frassoc_thick#cL.v2x_frassoc_thick ) label sca("r2" "N_g" "g_avg") obslast addnotes("Entries are regression coefficients, with standard errors clustered on countries, in parentheses. Country- and year-fixed effects included in regressions but omitted from the table.")

* TABLE 3:
* (H3) Linear effect of judicial constraints on the executive
eststo constraints1: qui xtreg v2x_execorr l.v2x_execorr l2.v2x_execorr c.l.v2x_polyarchy##c.l.v2x_polyarchy l.v2x_jucon l.polyarchy_stock10 i.year, fe cluster(country_id)
* (H4) Linear effect of legislative constraints on the executive
eststo constraints2: qui xtreg v2x_execorr l.v2x_execorr l2.v2x_execorr c.l.v2x_polyarchy##c.l.v2x_polyarchy l.v2xlg_legcon l.polyarchy_stock10 i.year, fe cluster(country_id)
esttab constraints1 constraints2 , b(4) se(4) star(* 0.10 ** 0.05 *** 0.01) replace nogaps keep(L.v2x_execorr L2.v2x_execorr L.v2x_polyarchy cL.v2x_polyarchy#cL.v2x_polyarchy L.v2x_jucon L.v2xlg_legcon) order (L.v2x_execorr L2.v2x_execorr L.v2x_polyarchy cL.v2x_polyarchy#cL.v2x_polyarchy L.v2x_elecreg L.v2x_jucon L.v2xlg_legcon) label sca("r2" "N_g" "g_avg") obslast addnotes("Entries are regression coefficients, with standard errors clustered on countries, in parentheses. Country- and year-fixed effects included in regressions but omitted from the table.")

* TABLE 4:
* (H5) Direct positive effect of elections
eststo elections1: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr l.v2x_elecreg l.polyarchy_stock10 i.year, fe cluster(country_id)
* (H6) Direct negative effect of free and fair elections
eststo elections2: qui xtreg v2x_corr l.v2x_corr l2.v2x_corr l.v2x_elecreg l.frefair2 l.polyarchy_stock10 i.year, fe cluster(country_id)
esttab elections1 elections2, b(4) se(4) star(* 0.10 ** 0.05 *** 0.01) replace nogaps keep (L.v2x_corr L2.v2x_corr L.v2x_elecreg L.frefair2) order (L.v2x_corr L2.v2x_corr L.v2x_elecreg L.frefair2) label sca("r2" "N_g" "g_avg") obslast addnotes("Entries are regression coefficients, with standard errors clustered on countries, in parentheses. Country- and year-fixed effects included in regressions but omitted from the table.")
